<template>
  <div class='questions-preview'>
    <!-- 题组详情弹出层 -->
    <el-dialog title="题目预览" :visible="showDetailsDialog" width="50%" @close="shutDownDailog">
      <el-row>
        <el-col :span="6"><div class="text">【题型】 :{{ basicQuestionBank.questionType | questionType }}</div></el-col>
        <el-col :span="6"><div class="text">【编号】 :{{ basicQuestionBank.id }}</div></el-col>
        <el-col :span="6"><div class="text">【难度】 :{{ basicQuestionBank.difficulty | difficulty }}</div></el-col>
        <el-col :span="6"><div class="text">【标签】 :{{ basicQuestionBank.tags }}</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="6"><div class="text">【学科】 :{{ basicQuestionBank.subjectName }}</div></el-col>
        <el-col :span="6"><div class="text">【目录】 :{{ basicQuestionBank.directoryName }}</div></el-col>
        <el-col :span="6"><div class="text">【方向】 :{{ basicQuestionBank.direction }}</div></el-col>
      </el-row>
      <el-divider></el-divider>
      <span>【题干】 :</span>
      <span style="color: blue" v-html="basicQuestionBank.question"></span>
      <p class="title" v-if="basicQuestionBank.questionType !== '3'">{{ basicQuestionBank.questionType | questionType }} 选项: ( 以下选中的选项为正确答案 )</p>
        <!-- 单选 -->
        <template v-if="basicQuestionBank.questionType === '1'">
            <el-radio
            v-for="(item,index) in basicQuestionBank.options"
            :key="index"
            :value="item.isRight"
            :label="1"
            class="block"
            >
              {{item.title}}
            </el-radio>
        </template>

        <!-- 多选 -->
        <template v-if="basicQuestionBank.questionType === '2'">
          <el-checkbox-group :value="checkList">
            <el-checkbox
             v-for="(item,index) in basicQuestionBank.options"
             :key="index"
             :label="item.isRight"
              class="block"
            >
              {{item.title}}
            </el-checkbox>
          </el-checkbox-group>
        </template>

      <el-divider></el-divider>
      <span style="margin-right: 10px">【参考答案】 :</span>
      <el-button type="danger" ref="answerBtn" @click="lookAnswerVideo = true">视频答案预览</el-button>
      <div>
        <video v-if="lookAnswerVideo" style="width: 400px;margin-top: 20px;" :src="basicQuestionBank.videoURL" controls="controls"></video>
      </div>
      <el-divider></el-divider>
      <div class="balanceLayout">
        <p>【答案解析】 :</p>
        <div v-html="basicQuestionBank.answer"></div>
      </div>

      <el-divider></el-divider>
      <span>【题目备注】 :{{ basicQuestionBank.remarks }}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="shutDownDailog">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { questionType, difficulty } from '../../api/hmmm/constants.js'
export default {
  name: 'QuestionsPreview',
  props: {
    showDetailsDialog: {
      type: Boolean,
      default: false
    },
    basicQuestionBank: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      lookAnswerVideo: false,
      // 单选选中项
      radio: 1,
      // TODO
      checkList: [1]
    }
  },
  filters: {
    // 题型过滤
    questionType (value) {
      const f = questionType.find(t => t.value === parseInt(value))
      return f ? f.label + '题' : ''
    },
    // 难度过滤
    difficulty (value) {
      const f = difficulty.find(t => t.value === parseInt(value))
      return f ? f.label : ''
    }
  },
  methods: {
    // 关闭操作
    shutDownDailog () {
      this.$emit('update:showDetailsDialog', false)
      this.lookAnswerVideo = false
    }
  }
}
</script>

<style scoped lang='less'>
.text{
  text-overflow:ellipsis;
  white-space:nowrap;
  overflow:hidden;
}
.balanceLayout{
  display: flex;
}
.title{
  margin-bottom: 10px;
}
.block{
  display: block;
  margin-bottom: 10px;
}
.el-divider--horizontal{
  margin: 10px 0;
}
</style>
